<?php

class Chinhanh extends CI_Controller {

    private $title = 'Liên hệ | Gia sư 7s - tìm hiểu thêm thông tin về chúng tôi';
    //private $chinhanh_model;

    public function __construct() {
        parent::__construct();
        $this->load->model("chinhanh_model");
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->model('quanly_contact_lienhe_model');
        session_start();
//        $_SESSION['id']=1;
    }

    public function index() {
        $this->form_validation->set_rules('name', 'Họ tên', 'trim|required|max_length[50]|xss_clean');
        $this->form_validation->set_rules('sdt', 'Số điện thoại', 'required|numeric');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('title', 'Tiêu đề', 'trim|required');
        $this->form_validation->set_rules('content', 'Nội dung', 'required');
        $this->form_validation->set_message('required', 'Mục này không được để trống.');
        $this->form_validation->set_message('numeric', 'Mục này chỉ được điền số.');
        $this->form_validation->set_message('valid_email', 'Email không hợp lệ.');
//    $data['chinhanh']= $this->chinhanh_model->loadData();
//    $this->load->view("user/lienhe/chinhanh",$data);
        $data['title'] = $this->title;
        $data = Array
            (
            'hoten' => $this->input->post('name'),
            'email' => $this->input->post('email'),
            'tieude' => $this->input->post('title'),
            'noidung' => $this->input->post('content'),
        );
        if ($this->form_validation->run() == FALSE) {
            $data['chinhanh'] = $this->chinhanh_model->loadData();
            $this->showUI('user/lienhe/lienhe_view', $data);
        } else {
            if ($this->form_validation->run() == FALSE) {
                $this->showUI('user/lienhe/lienhe_view', $data);
            } else {
                $this->quanly_contact_lienhe_model->add($data);
                $this->showUI('user/lienhe/thankforfeedback', $data);
            }
        }
    }

    public function chinhanh1($a) {
        $data['chinhanh'] = $this->chinhanh_model->load_chinhanh($a);
        $this->showUI('user/lienhe/chinhanh', $data);
    }

    function showUI($path, $data) {
        $data['title'] = $this->title;
        $this->load->view('user/common/header_view', $data);
        $this->load->view('user/common/left_sidebar_view', $data);
        $this->load->view('user/common/head_content_view', $data);
        $this->load->view($path, $data);
        $this->load->view('user/common/right_sidebar_view', $data);
        $this->load->view('user/common/footer_view', $data);
    }

}

